
function Picnews(args) {
	this.picnews = $(args.id);
	this.ais = this.picnews.find("a").not(this.picnews.find(".list a"));
	this.current = 0;
	this.intervalID = null;
	this.interval = 3000;
}
Picnews.prototype = {
	start: function() {
		this.stop();
		this.intervalID = window.setInterval(function() {}, this.interval);
	},
	stop: function() {
		window.clearInterval(this.intervalID);
	},
	next: function(index) {
		this.ais.eq(index)
	}
};

$(function() {
	var timeout = null;
	var ps = $(".picnews a").not(".picnews .list a");
	ps.each(function(i, d) {
		var a = $("<a href=\"javascript:\"></a>").html(i + 1).click(function() {
			$(this).blur();
			var current = $(".picnews .list .current");
			if (current[0] === this) {
				return false;
			}
			current.removeClass("current");
			$(this).addClass("current");
			
			window.clearTimeout(timeout);
			ps.filter(".current").fadeOut(300, function() {
				$(".picnews .title").html(ps.eq(i).attr("title"));
				ps.removeClass("current").eq(i).addClass("current").fadeIn(300);
			});
			timeout = window.setTimeout(function() {
				if (ps.length - 1 < i + 1) {
					$(".picnews .list a").eq(0).click();
				} else {
					$(".picnews .list a").eq(i + 1).click();
				}
			}, 3000);
		}).addClass(0 === i ? "current" : "").mouseover(function() {return false; $(this).click();});
		
		$(".picnews .list").append(a);
	});
});
